﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TransFormer.Web.admin
{
    public partial class KeyWords : AdminPage
    {
        private BLL.KeyWords _keybll = new BLL.KeyWords();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            Model.KeyWords model = new Model.KeyWords();
            switch (PageNameDDL.SelectedValue)
            {
                case "Index":
                    model = _keybll.GetModel(1);
                    break;
                case "About":
                    model = _keybll.GetModel(2);
                    break;
                case "Product":
                    model = _keybll.GetModel(3);
                    break;
                case "Support":
                    model = _keybll.GetModel(4);
                    break;
                case "Contact":
                    model = _keybll.GetModel(5);
                    break;
                case "Service":
                    model = _keybll.GetModel(6);
                    break;
            }
            if (model == null) return;
            txtKeyWords.Text = model.KeyContent;
            txtDesc.Text = model.PageDesc;
            PageTitle.Text = model.Title; 
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (!IsValid) return;
            Model.KeyWords model = new Model.KeyWords();
            switch (PageNameDDL.SelectedValue)
            {
                case "Index":
                    model = _keybll.GetModel(1);
                    break;
                case "About":
                    model = _keybll.GetModel(2);
                    break;
                case "Product":
                    model = _keybll.GetModel(3);
                    break;
                case "Support":
                    model = _keybll.GetModel(4);
                    break;
                case "Contact":
                    model = _keybll.GetModel(5);
                    break;
                case "Service":
                    model = _keybll.GetModel(6);
                    break;
            }
            if (model == null) return;
            model.KeyContent = txtKeyWords.Text;
            model.PageDesc = txtDesc.Text;
            model.Title = PageTitle.Text;
            _keybll.Update(model);

        }

        protected void PageNameChanged(object sender, EventArgs e)
        {

            Model.KeyWords model = new Model.KeyWords();
            switch (PageNameDDL.SelectedValue)
            {
                case "Index":
                    model = _keybll.GetModel(1);
                    break;
                case "About":
                    model = _keybll.GetModel(2);
                    break;
                case "Product":
                    model = _keybll.GetModel(3);
                    break;
                case "Support":
                    model = _keybll.GetModel(4);
                    break;
                case "Contact":
                    model = _keybll.GetModel(5);
                    break;
                case "Service":
                    model = _keybll.GetModel(6);
                    break;
            }
            if (model == null) return;
            txtKeyWords.Text = model.KeyContent;
            txtDesc.Text = model.PageDesc;
            PageTitle.Text = model.Title; 
        }
    }
}